package  
{
	import org.flixel.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class BossPattern 
	{
		public var pattern:Array;
		public var time:Number;
		public var lastEndTime:Number;
		public function BossPattern() 
		{
			pattern = [];
			time = 0;
			lastEndTime = 0;
		}	
		
		public function addTurretTime(start:Number, end:Number, turret:Turret):void
		{
			pattern.push([start, end, turret]);
			GameState.ref.turrets.add(turret);
			lastEndTime = Math.max(lastEndTime, end);
		}
		
		public function setPatternLength(end:Number):void
		{
			lastEndTime = end;
		}
		
		public function update():void
		{
			time += FlxG.elapsed;
			if (time > lastEndTime) { time -= lastEndTime; }
			for (var i:int = 0; i < pattern.length; i++)
			{
				var start_end_turret:Array = pattern[i];
				if (start_end_turret[0] <= time && start_end_turret[1] > time)
				{
					(start_end_turret[2] as Turret).spawn();
				}
				else
				{
					(start_end_turret[2] as Turret).exists = false;
				}
			}
		}
		
		public function patternStart():void
		{
			for (var i:int = 0; i < pattern.length; i++)
			{
				var start_end_turret:Array = pattern[i];
				GameState.ref.turrets.add(start_end_turret[2]);
			}
		}
		
		public function patternEnd():void
		{
			GameState.ref.turrets.clear();
		}
		
	}

}